cmake_minimum_required(VERSION 3.10)

project(db)

#execute cmake，then delete old files. 


aux_source_directory(./src SRC)

#include_directories
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_INCLUDE_OUTPUT_DIRECTORY}/logger)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common/include)

file(GLOB_RECURSE COMMON_INC "${CMAKE_CURRENT_SOURCE_DIR}/../common/include/threadPool.h" "${CMAKE_CURRENT_SOURCE_DIR}/../common/include/threadLock.h")
file(GLOB_RECURSE COMMON_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../common/src/threadPool.c" "${CMAKE_CURRENT_SOURCE_DIR}/../common/src/threadLock.c")

#library_directories
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)
link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})

#add_executable(db ${SRC}) # 生成可执行文件
#add_library(db STATIC ${SRC}) # 生成静态库
add_library(db SHARED ${SRC} ${COMMON_INC} ${COMMON_SRC}) # 生成动态库或共享库
TARGET_LINK_LIBRARIES(${PROJECT_NAME} libEasyLogger.so)
# SET_TARGET_PROPERTIES(db PROPERTIES VERSION 1.0.0 SOVERSION 1)

install(TARGETS db  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBRARY_DIR})

 add_custom_command(TARGET  db
  POST_BUILD
  COMMAND echo "db manager builded finished."
  COMMAND ${CMAKE_COMPILER_STRIP} "$<TARGET_FILE:db>"
  #COMMAND ${CMAKE_COMMAND} -E copy  "${CMAKE_CURRENT_SOURCE_DIR}/include/CDBManager.h" ${CMAKE_INCLUDE_PATH}/CDBManager.h
  #COMMAND ${CMAKE_COMMAND} -E copy  "${CMAKE_CURRENT_SOURCE_DIR}/include/dbif.h" ${CMAKE_INCLUDE_PATH}/dbif.h
#  COMMAND ${CMAKE_COMMAND} -E copy  $<TARGET_FILE:db> ${CMAKE_LIBRARY_PATH}/libdb.so 
#  COMMENT  "db manager is install finished"
 )